using Boo.Lang;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;

[Serializable]
public class DragRigidbodyarcade : MonoBehaviour
{
	[Serializable]
	[CompilerGenerated]
	internal sealed class _0024DragObject_0024328 : GenericGenerator<object>
	{
		internal float _0024distance_0024334;

		internal DragRigidbodyarcade _0024self__0024335;

		public _0024DragObject_0024328(float distance, DragRigidbodyarcade self_)
		{
			_0024distance_0024334 = distance;
			_0024self__0024335 = self_;
		}

		public override IEnumerator<object> GetEnumerator()
		{
			return new _0024(_0024distance_0024334, _0024self__0024335);
		}
	}

	[Serializable]
	[CompilerGenerated]
	internal sealed class _0024destroy_0024336 : GenericGenerator<WaitForSeconds>
	{
		internal DragRigidbodyarcade _0024self__0024338;

		public _0024destroy_0024336(DragRigidbodyarcade self_)
		{
			_0024self__0024338 = self_;
		}

		public override IEnumerator<WaitForSeconds> GetEnumerator()
		{
			return new _0024(_0024self__0024338);
		}
	}

	[Serializable]
	[CompilerGenerated]
	internal sealed class _0024ld_0024339 : GenericGenerator<WaitForSeconds>
	{
		internal DragRigidbodyarcade _0024self__0024341;

		public _0024ld_0024339(DragRigidbodyarcade self_)
		{
			_0024self__0024341 = self_;
		}

		public override IEnumerator<WaitForSeconds> GetEnumerator()
		{
			return new _0024(_0024self__0024341);
		}
	}

	public Rigidbody body;

	public Transform tr;

	public Transform box;

	public GameObject launcher;

	public spin blade;

	public Rigidbody bey;

	public float spring;

	public float damper;

	public float drag;

	public float angularDrag;

	public float distance;

	public bool attachToCenterOfMass;

	public float speed;

	public float speedo;

	public bool LeftHanded;

	public int fstart;

	public Camera mainCamera;

	private SpringJoint springJoint;

	private SpringJoint springJoint1;

	public DragRigidbodyarcade()
	{
		spring = 50f;
		damper = 5f;
		drag = 10f;
		angularDrag = 5f;
		distance = 0.2f;
	}

	public void Start()
	{
		if (PlayerPrefs.GetInt("LeftHanded") == 1)
		{
			LeftHanded = true;
		}
		if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name.Contains("MP"))
		{
			Invoke("find", 0.2f);
			body = GetComponent<Rigidbody>();
			tr = transform;
		}
		else
		{
			body = GetComponent<Rigidbody>();
			tr = transform;
			StartCoroutine(this.destroy());
		}
		GameObject gameObject = new GameObject("Rigidbody dragger");
		Rigidbody rigidbody = gameObject.AddComponent<Rigidbody>() as Rigidbody;
		destroy destroy = gameObject.AddComponent<destroy>() as destroy;
		springJoint1 = (gameObject.AddComponent<SpringJoint>() as SpringJoint);
	}

	public void Update()
	{
		speedo = body.velocity.magnitude * 19f + 0.1f;
		if (fstart == 0)
		{
			blade.spinvelocity = (int)speed;
		}
		else
		{
			blade.spinvelocity = 50;
		}
		if (!Input.GetMouseButtonDown(0))
		{
			return;
		}
		RaycastHit hitInfo = default(RaycastHit);
		if (Physics.Raycast(mainCamera.ScreenPointToRay(UnityEngine.Input.mousePosition), out hitInfo, 100f) && (bool)hitInfo.rigidbody && !hitInfo.rigidbody.isKinematic && !hitInfo.rigidbody.useGravity)
		{
			if (!springJoint)
			{
				StartCoroutine(this.destroy());
				GameObject gameObject = new GameObject("Rigidbody dragger");
				Rigidbody rigidbody = gameObject.AddComponent<Rigidbody>() as Rigidbody;
				destroy destroy = gameObject.AddComponent<destroy>() as destroy;
				springJoint = (gameObject.AddComponent<SpringJoint>() as SpringJoint);
				rigidbody.isKinematic = true;
			}
			springJoint.transform.position = hitInfo.point;
			if (attachToCenterOfMass)
			{
				Vector3 position = transform.TransformDirection(hitInfo.rigidbody.centerOfMass) + hitInfo.rigidbody.transform.position;
				position = springJoint.transform.InverseTransformPoint(position);
				springJoint.anchor = position;
			}
			else
			{
				springJoint.anchor = Vector3.zero;
			}
			springJoint.spring = spring;
			springJoint.damper = damper;
			springJoint.maxDistance = distance;
			springJoint.connectedBody = hitInfo.rigidbody;
			StartCoroutine("DragObject", hitInfo.distance);
		}
	}

	public IEnumerator DragObject(float distance)
	{
		return new _0024DragObject_0024328(distance, this).GetEnumerator();
	}

	public void LateUpdate()
	{
		if ((bool)springJoint && Input.GetMouseButtonUp(0))
		{
			blade.spin();
			StartCoroutine(ld());
		}
		if (!(speedo <= speed))
		{
			speed = speedo * 1.1f;
		}
	}

	public IEnumerator destroy()
	{
		return new _0024destroy_0024336(this).GetEnumerator();
	}

	public IEnumerator ld()
	{
		return new _0024ld_0024339(this).GetEnumerator();
	}

	public void find()
	{
		blade = (((spin)GameObject.Find("PlayerPrefab(Clone)").GetComponent(typeof(spin))) as spin);
		bey = GameObject.Find("PlayerPrefab(Clone)").GetComponent<Rigidbody>();
		StartCoroutine(destroy());
	}

	public void Main()
	{
	}
}
